GBML manual / Maps

map_remove

Removes key (and its value) from target if present. Returns true if something was removed, false if key was not present (target is unchanged either way, never an error).

Syntax

map_remove(target, key) -> bool

Arguments

NameType
targetmap
keymapkey

Returns

bool

Description

Removes key (and its value) from target if present. Returns true if something was removed, false if key was not present (target is unchanged either way, never an error).

Example

/// @type {map<string,int>}
var scores = {};
map_set(scores, "alice", 10);
var removed = map_remove(scores, "alice"); // true - alice was present
var removed_again = map_remove(scores, "alice"); // false - alice is already gone
A real capture - the map holding alice - 10, before the removeA real capture - the map holding alice - 10, before the remove
A real capture - the map holding alice - 10, before the remove
The same map after map_remove(scores, "alice") - empty, alice is goneThe same map after map_remove(scores, "alice") - empty, alice is gone
The same map after map_remove(scores, "alice") - empty, alice is gone

On the GBA

The hash map's erase(key) - O(1) average.

See also: map_setmap_hasmap_getmap_clearData containers